package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.DigitalIOButton;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.templates.commandGroups.DriveInASquare;

/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
    //// CREATING BUTTONS
    // One type of button is a joystick button which is any button on a joystick.
    // You create one by telling it which joystick it's on and which button
    // number it is.
    // Joystick stick = new Joystick(port);
    // Button button = new JoystickButton(stick, buttonNumber);
    
    // Another type of button you can create is a DigitalIOButton, which is
    // a button or switch hooked up to the cypress module. These are useful if
    // you want to build a customized operator interface.
    // Button button = new DigitalIOButton(1);
    
    // There are a few additional built in buttons you can use. Additionally,
    // by subclassing Button you can create custom triggers and bind those to
    // commands the same as any other Button.
    
    //// TRIGGERING COMMANDS WITH BUTTONS
    // Once you have a button, it's trivial to bind it to a button in one of
    // three ways:
    
    // Start the command when the button is pressed and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenPressed(new ExampleCommand());
    
    // Run the command while the button is being held down and interrupt it once
    // the button is released.
    // button.whileHeld(new ExampleCommand());
    
    // Start the command when the button is released  and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenReleased(new ExampleCommand());
    private Joystick drivingJoystick; // left joystick on driver station (drive)
    private JoystickButton trigger; // joystick button to be used to trigger a cmd
    
    private Joystick camControlJoystick; // right joystick on driver station (cam)
    
    public OI() {
        /**
         * Create a joystick object. We will use the left joystick for driving
         */
        drivingJoystick= new Joystick(RobotMap.JOYSTICK_LEFT_PORT);
        
        /**
         * Create another joystick object. We will use the right joystick for 
         * moving the camera
         */
        camControlJoystick= new Joystick(RobotMap.JOYSTICK_RIGHT_PORT);
        
        /**
         * Create a joystick button object for the joystick's top button.
         * Note: The joystick class by default defines button 2 as the top button
         */
        trigger= new JoystickButton(drivingJoystick,Joystick.ButtonType.kTop.value);
        
        /**
         * Set up a trigger such that when the mapped button is pressed, the
         * robot will drive in a square (using a command group)
         * Note: This particular command group will invoke commands to 
         * control the drive train (chassis) subsystem.
         */
        trigger.whenPressed(new DriveInASquare());
    }
    /**
     * This method returns the current joystick object
     * @return Current joystick 
     */
    public Joystick getDriveJoystick() {
        return drivingJoystick;
    }
    public Joystick getCamControlJoystick() {
        return camControlJoystick;
    }
}


